385D - Bear and Floodlight - CodeForces Solution


bitmasks dp geometry *2200

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <iomanip>

struct LightHouse {
    long double x_{0};
    long double y_{0};
    long double a_{0};
};

long double Dist(const LightHouse& lh, long double d, long double r) {
    if (d == r) {
        return r;
    }
    long double pi = std::acos(-1.0);
    long double rad = (pi * lh.a_) / 180.0;
    std::pair<long double, long double> p = std::make_pair((d - lh.x_) * std::cos(rad) + lh.y_ * std::sin(rad),
                                                           (d - lh.x_) * std::sin(rad) - lh.y_ * std::cos(rad));

    if (p.second > -1e-10) {
        return r;
    }

    p.first /= p.second;
    return std::min(std::max(lh.x_ - lh.y_ * p.first, d), r);
}

long double MaxPath(long double l, long double r, const std::vector<LightHouse>& v) {
    std::vector<long double> opt(1 << (v.size()), l);
    for (size_t i = 0; i < (1 << (v.size())); i++) {
        for (size_t j = 0; j < v.size(); j++) {
            if (!((i >> j) & 1)) {
                opt[(i | (1 << j))] = std::max(opt[(i | (1 << j))], Dist(v[j], opt[i], r));
            }
        }
    }
    return opt.back() - l;
}

int main() {
    size_t n = 0;
    std::cin >> n;
    long double l = 0;
    long double r = 0;
    std::cin >> l >> r;
    std::vector<LightHouse> v(n);
    for (size_t i = 0; i < n; i++) {
        std::cin >> v[i].x_ >> v[i].y_ >> v[i].a_;
    }
    std::cout << std::fixed;
    std::cout.precision(8);
    std::cout << MaxPath(l, r, v);
    return 0;
}


Comments

Submit
0 Comments
More Questions

1665D - GCD Guess
29A - Spit Problem
1097B - Petr and a Combination Lock
92A - Chips
1665B - Array Cloning Technique
1665A - GCD vs LCM
118D - Caesar's Legions
1598A - Computer Game
1605A - AM Deviation
1461A - String Generation
1585B - Array Eversion
1661C - Water the Trees
1459A - Red-Blue Shuffle
1661B - Getting Zero
1661A - Array Balancing
1649B - Game of Ball Passing
572A - Arrays
1455A - Strange Functions
1566B - MIN-MEX Cut
678C - Joty and Chocolate
1352E - Special Elements
1520E - Arranging The Sheep
1157E - Minimum Array
1661D - Progressions Covering
262A - Roma and Lucky Numbers
1634B - Fortune Telling
1358A - Park Lighting
253C - Text Editor
365B - The Fibonacci Segment
75A - Life Without Zeros